#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
#include <strings.h>  //for bzero
using namespace std;

#ifndef _SOCKBASE_H_
#define _SOCKBASE_H_

class SockClient{
	public:
		SockClient();
		~SockClient();
		
		/* create socket descriptor */	
		bool Socket();

		/* set sockaddr structure */
		bool SetAddr(string ip,short port);

		/* build connection */
		bool Connect();

		/* message communication */
		bool Send();
		bool Receive();
		
		string GetErr(){
			return errMessage;	
		}
		
	private:
		void Err(){
			errMessage = strerror(errno);
		}
		
	public:
		bool StartClient(string ip,short port);
		
	private:
		int sockfd;
		struct sockaddr_in servaddr;
		struct sockaddr_in cliaddr;
		socklen_t servaddrlen;
		socklen_t cliaddrlen;
		char* inBuf;
		char* outBuf;
		string errMessage;
};

#endif
